#include <stdio.h>

int compareFile(void);

int main(){
  if(compareFile())
    printf("Files are Equal!\n");
  else
    printf("Files are not equal.\n");
  return(0);
}

// Returns 1 if they are equal and 0 otherwise
int compareFile(void){
  int data1, data2;
  FILE *filePtr1, *filePtr2;
  
  filePtr1 = fopen("file1.dat","r");
  filePtr2 = fopen("file2.dat","r");

  if((filePtr1 == NULL)||(filePtr2 == NULL)){
    printf("ERROR opening files\n");
    if (filePtr1 == NULL && filePtr2 == NULL)
      return 0;
    else if (filePtr1 == NULL){
      fclose(filePtr2);
      return 0;
    }
    else{
      fclose(filePtr1);
      return 0;
    }
  }
  else{ 
    while(!feof(filePtr1)){
      fscanf(filePtr1, "%d", &data1);
      fscanf(filePtr2, "%d", &data2);
      if(data1 != data2){
        fclose(filePtr1);
        fclose(filePtr2);
        return(0);
      }
    }
    fclose(filePtr1);
    fclose(filePtr2);
    return(1);
  }
}
